package dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import entidade.CompraRevista;

public class CompraRevistaDAO {
		
	    private Connection connection;

	    public CompraRevistaDAO() throws SQLException
	    {
	        this.connection = ConnectionFactory.getConnection();
	    }
	    
	    public List<CompraRevista> getCompras(Date dataInicio, Date dataFim , List<String> StatusPagamento ) throws SQLException
	    {
			String sql = "select distinct compra_revista.* from compra_revista";
			/**if(StatusPagamento != null)
			{
				int i=0;
				while(!StatusPagamento.isEmpty())
				{
					sql += " and IDFormaPagamento like '" +  StatusPagamento.get(i) + "'";
				}
			}
			if(dataInicio != null && dataFim != null)
			{
				sql += " and DataCompra between '" + dataInicio.toString() + "' and '" + dataFim.toString()+ "'" ; 
			}
			**/
			System.out.println(sql);
			
			PreparedStatement stmt = connection.prepareStatement(sql);
			ResultSet rs = stmt.executeQuery();
			ArrayList<CompraRevista> compras = new ArrayList<CompraRevista>();
			while(rs.next())
			{
				CompraRevista cr = new CompraRevista();
				cr.setCpf(rs.getString("CPF"));
				cr.setDataCompra(rs.getDate("DataCompra").toString());
				cr.setFormaPagamento(String.valueOf(rs.getInt("IDFormaPagamento" )));
				cr.setIdCompraRevista(String.valueOf(rs.getInt("IDCompraRevista")));
				cr.setSituacao(rs.getString("Situacoes"));
				compras.add(cr);				
			}
			rs.close();
			stmt.close();
			return compras;
	    	
	    }
	
}
